<?php
include_once('common/header.php');	
if($AppUI->id <= 0 || !isset($_SERVER['HTTP_REFERER'])) {
	$arrJson = array('error'=>1,'msg'=>$arrError[1]);
	echo Zend_Json::encode($arrJson);
	exit();
}
$strRefer		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$intUserId		= $AppUI->id;
$intPlaceId		= $objRequest->getParam('placeid', 0);
$strNote		= $objRequest->getParam('note', '');
$oFile			= isset($_FILES['pimage']) ? $_FILES['pimage'] : null;
$strToken		= $objRequest->getParam('token', '');
$strSession		= Vfriend_Function::getSecret($intUserId, SE_PLACE_UPLOAD_IMG);
$intError		= 0;
$strImage		= '';
$intTotal		= 0;
$objPlace 		= new Place();
$intTotalImg	= $objPlace->getImageTotal($intPlaceId);
if($intTotalImg >= PLACE_IMG_LIMIT)
	$intError = 31;
if($intError == 0 && $oFile['name'] != '') {
	$arrImage	= Vfriend_Upload::uploadPlaceImg($oFile, $strImage);
	if($arrImage['error'] > 0) {
		$intError = 29;
	}
} else if($intError == 0 && !$oFile['name']){
	$intError = 30;
}
if(Vfriend_Function::isValidLink($strRefer)  && $strToken != '' && $strToken == $strSession) {	
	Vfriend_Function::deleteSecret($intUserId, SE_PLACE_UPLOAD_IMG);
	$intError	= $objPlace->addImage($intUserId, $intPlaceId, $strImage, $strNote);	
	if($intError > 0) {
		$intError	= 28;
	}	
} else {
	$intError	= 26;
}
if($intError > 0) {
	$strMessage	= $arrError[$intError];
} else {
	$strMessage	= $arrMessage[14];
}
$arrJson = array('error'=>$intError,'msg'=>$strMessage);
echo Zend_Json::encode($arrJson);
exit();
?>
